﻿#ifndef MODBUSTCPCLIENT_H
#define MODBUSTCPCLIENT_H

#include <QModbusTcpClient>
#include <QObject>
#include <QUrl>
#include "PLCClientBase.h"

class ModbusTcpClient : public PLCClientBase
{
    Q_OBJECT
public:
    explicit ModbusTcpClient(const QString& name = "", QObject *parent = nullptr);
    virtual ~ModbusTcpClient();
public:
    virtual void initCom() override;

protected:
    virtual void processData(const PLCRequestData& requestData){}
    virtual void sendReadData(const PLCRequestData& data) override;
    virtual void sendWriteData(const PLCRequestData& data) override;

private:
    QModbusTcpClient* modbusDevice;
    void onWriteReady();
    void onReadReady();
    void onErrorOccurred(QModbusDevice::Error newError);
    void onStateChanged(QModbusDevice::State state);
};

#endif // MODBUSTCPCLIENT_H
